package com.example.classcommunity3.service;

import com.example.classcommunity3.dao.StudentDao;
import com.example.classcommunity3.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

//业务逻辑
@Service
public class StudentService {

    @Autowired
    StudentDao studentDao;      //数据操作

    public boolean signIn(Long account, String name) {

        boolean b;

        try {
            Student insertStudent = new Student();
            insertStudent.setStuAccount(account);
            insertStudent.setsName(name);
            studentDao.save(insertStudent);
            b = true;
        } catch (Exception e) {
            b = false;
        }
        return b;
    }

    public boolean changeInfo(Long account, String name) {
        Student student = studentDao.findByStuAccount(account);

        if (student != null) {
            try {
                student.setsName(name);
                studentDao.save(student);
                return true;
            } catch (Exception e) {
                return false;
            }
        }
        return false;
    }

    public String getStuName(Long account){
        String name;
        Student student = studentDao.findByStuAccount(account);

        name = student.getsName();
        return name;
    }
}
